package org.example.spring05.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;

//@Configuration
public class DataSourceConfig {

    /*
       测试环境下
     */
    @Bean
    @Profile("test")
    public MyDataSource test(){
        MyDataSource myDataSource = new MyDataSource();
        myDataSource.setUrl("jdbc:mysql://localhost:3306/test");
        myDataSource.setUsername("test01");
        myDataSource.setPassword("123456");
        return myDataSource;
    }

    /*
      开发环境下
    */
    @Bean
    @Profile({"dev","default"})
    public MyDataSource dev(){
        MyDataSource myDataSource = new MyDataSource();
        myDataSource.setUrl("jdbc:mysql://localhost:3306/dev");
        myDataSource.setUsername("dev01");
        myDataSource.setPassword("123456");
        return myDataSource;
    }

    /*
      生产环境
     */
    @Bean
    @Profile("prod")
    public MyDataSource prod(){
        MyDataSource myDataSource = new MyDataSource();
        myDataSource.setUrl("jdbc:mysql://localhost:3306/prod");
        myDataSource.setUsername("prod01");
        myDataSource.setPassword("dfdffdfs7678");
        return myDataSource;
    }
}
